package leetcode.new_wrold;

public class T36 {
    public boolean isValidSudoku(char[][] board) {
        boolean[][] row = new boolean[10][10];
        boolean[][] col = new boolean[10][10];
        boolean[][] box = new boolean[10][10];

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                char ch  = board[i][j];
                if (ch=='.') continue;
                int k = ch-'0';
                int z = i/3 * 3 + j/3;
                if (row[i][k] || col[j][k] || box[z][k]) {
                    return false;
                }
                row[i][k] = true;
                col[j][k] = true;
                box[z][k] = true;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        T36 t36 = new T36();
        char[][] board = new char[][]{
                {'.','.','4','.','.','.','6','3','.'}
                ,{'.','.','.','.','.','.','.','.','.'}
                ,{'5','.','.','.','.','.','.','9','.'}
                ,{'.','.','.','5','6','.','.','.','.'}
                ,{'4','.','3','.','.','.','.','.','1'}
                ,{'.','.','.','7','.','.','.','.','.'}
                ,{'.','.','.','5','.','.','.','.','.'}
                ,{'.','.','.','.','.','.','.','.','.'}
                ,{'.','.','.','.','.','.','.','.','.'}
        };
        boolean validSudoku = t36.isValidSudoku(board);
        System.out.println(validSudoku);
    }
}
/*
* [[".",".","4",".",".",".","6","3","."]
* ,[".",".",".",".",".",".",".",".","."]
* ,["5",".",".",".",".",".",".","9","."]
* ,[".",".",".","5","6",".",".",".","."]
* ,["4",".","3",".",".",".",".",".","1"]
* ,[".",".",".","7",".",".",".",".","."]
* ,[".",".",".","5",".",".",".",".","."]
* ,[".",".",".",".",".",".",".",".","."]
* ,[".",".",".",".",".",".",".",".","."]]*/